import { getPasswordConfigApi } from "@/api/configCenter/passwordManagement";

export default function OperationHook(state: Base.GeneraDataType) {
  const { searchForm, tableData, dialogOpts, loading } = state;
  const getData = () => {
    loading.value = true;
    return getPasswordConfigApi()
      .then((res: any) => {
        const { code, data } = res;
        if (code === 200) {
          tableData.value = data || [];
          searchForm.total = data.length;
        }
      })
      .finally(() => {
        loading.value = false;
      });
  };
  const searchHandle = () => {
    searchForm.pageNum = 1;
    getData();
  };

  const addHandle = () => {
    dialogOpts.title = "设置日期";
    dialogOpts.width = "520px";
    dialogOpts.type = 1;
    dialogOpts.component = "ModifyDate";
    dialogOpts.visible = true;
  };

  const editHandle = (row: PasswordManagement.ListRows) => {
    dialogOpts.title = "设置日期";
    dialogOpts.width = "520px";
    dialogOpts.type = 2;
    dialogOpts.component = "ModifyDate";
    dialogOpts.passData = row;
    dialogOpts.visible = true;
  };

  return {
    searchHandle,
    getData,

    addHandle,
    editHandle
  };
}
